package com.tanhua.server.controller;

import com.tanhua.model.dto.Answer;
import com.tanhua.model.dto.AnswerDto;
import com.tanhua.model.mongo.Report;
import com.tanhua.model.mongo.Questionnaire;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wjs
 * @version 1.0
 * @date 2022/1/8 0008 下午 6:52
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 测灵魂-提交问卷（学生实战）
     * @param answers
     * @return
     */
    @PostMapping
    public ResponseEntity testSoul(@RequestBody AnswerDto answers){
        String reportId = testSoulService.save(answers);
        return ResponseEntity.ok(reportId);
    }

    /**
     * 测灵魂-查看结果（学生实战）
     * @param id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity report(@PathVariable("id") String id){
        ReportVo vo = testSoulService.findByReportId(id);
        return ResponseEntity.ok(vo);
    }

    /**
     * 测灵魂-问卷列表（学生实战）
     * @return
     */
    @GetMapping()
    public ResponseEntity testSoul(){
        List<QuestionnaireVo> vos = testSoulService.findQuestionnaire();
        return ResponseEntity.ok(vos);
    }
}
